import axios from 'axios'
import sign from './sign'

// 请求接口地址
const host = 'https://wb.renqidaren.com/api/v1' //正式接口地址
// const host = 'http://192.168.2.100:8000/api/v1' // 测试接口地址


const request = async (url, method = 'get', params, tokenpatch) => {
    let token = localStorage.getItem('token')
    let response;
    url = host + url;
    sign.signOfParam(params)
    if (method == 'get') {
        response = await axios.get(url, {
            headers: {
                'Authorization': 'Bearer ' + token
            },
            params: params
        })
    }else{
        let token = localStorage.getItem('token')
        if(token){
            response = await axios({
                url: url,
                method: 'post',
                data: params,
                headers: {
                    'Authorization': 'Bearer ' + token,
                    // 'Contennt-Type': 'application/x-www-from-urlencoded'
                }
            })
        }else {
            response = await axios({
                url: url,
                method: 'post',
                data: params,
            })
        }

    }

    return response
}
export default {
    request
}
